var ctx;

var couponstate = "";
var couponid;
var pSize;

function setCtx(ctx){
	this.ctx = ctx;
}
function gotoPage(page){
	couponstate = ifNull($("#couponstate").val());
	couponid = ifNull($("#couponid").val());
	pSize = ifNull($("#pSize").val());
	loadContent("/couponInfo/couponDetailList?pNo="+ page+"&id="+couponid +"&couponstate="+ couponstate + "&pSize="+ pSize);
}

function gotoCouponDetailPage(page) {
	if(page == null){
		page = $(".inputclass").val();
	}
	var couponid = ifNull($("#couponid").val());
	couponstate = $("#couponstate").val();
	loadContent("/couponInfo/couponDetailList?pNo="+ page +"&id="+couponid+"&couponstate="+ couponstate + "&pSize="+ pSize);
}

function ifNull(mess){
	if(mess == null || mess == undefined){
		mess = "";
	}
	
	return mess;
}

//条件搜索菜单列表
function getCouponDetailList(){
	couponstate = $("#couponstate").val();
	couponid = $("#couponid").val();
	pSize = ifNull($("#pSize").val());
	
	loadContent("/couponInfo/couponDetailList?pNo=1"+"&id="+couponid+"&couponstate="+ couponstate + "&pSize="+ pSize);
	
}



//function deleteByIds(){
//	if($("img[name='couponDetailChecked'][src*=honggou]").length == 0){
//		layer.msg("请选择要删除的记录!",{
//icon: 3,
//time: 2000 //2秒关闭（如果不配置，默认是3秒）
//});
//	}else{
//		var delIds = [];
//		    $("#tableTbody img[name='couponDetailChecked'][src*=honggou]").each(function(){ 
//		    	delIds.push($(this).attr("class")); 
//		    }); 
//		    var vals = delIds.join(',');//转换为逗号隔开的字符串 
//			layer.confirm('确认删除?', {icon: 3, title:'提示'}, function(index){
//			    //do something
//				$.post(ctx+"/couponInfo/deleteDetailByPrimaryKey",{
//					ids:vals
//				},function(data){
//					if(data.success){
//						layer.msg("删除成功",{
//							icon: 1,
//							time: 2000 //2秒关闭（如果不配置，默认是3秒）
//						},function(){
//							loadContent("/couponInfo/couponDetailList");
//						});
//					} else {
//						layer.msg(data.msg,{
//							icon: 2,
//							time: 2000 //2秒关闭（如果不配置，默认是3秒）
//						});
//					}
//				});
//			    layer.close(index);
//			});
//
//		
//	}
//}

//返回上一页
function cancel(){
	loadContent("/couponInfo/couponInfoList"); 
}

//导出优惠券发放和使用情况
function exportExcel() {
	couponstate = $("#couponstate").val();
	var id = ifNull($("#couponid").val());
	var total = ifNull($("#total").val());
	if(total >0) {
		location.href=ctx +"/couponInfo/exportCouponDetailExcel?id="+ id + "&couponstate=" + couponstate ;
	} else {
		layer.msg("未获取到数据，无法导出...",{
			icon: 2,
			time: 2000 //2秒关闭（如果不配置，默认是3秒）
		});
	}
	
}